package com.ddone.finance.controller.api;


import com.baomidou.mybatisplus.extension.api.R;
import com.ddone.base.util.JwtUtils;
import com.ddone.common.result.Response;
import com.ddone.finance.pojo.entity.BorrowInfo;
import com.ddone.finance.service.BorrowInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author ddone
 * @since 2024-04-10
 */
@RestController
@RequestMapping("/core/api/borrowInfo")
@Api(tags = {"借款信息"})
public class BorrowInfoController {
    @Resource
    private BorrowInfoService borrowInfoService;

    @ApiOperation("获取借款额度")
    @GetMapping("/getBorrowAmount")
    public Response<Object> getBorrowAmount(@RequestHeader("token") String token) {
        Long userId = JwtUtils.getUserId(token);
        BigDecimal borrowAmount = borrowInfoService.getBorrowAmount(userId);
        return Response.ok(borrowAmount);
    }

    @ApiOperation("提交借款申请")
    @PostMapping()
    public Response<Object> save(@RequestBody BorrowInfo borrowInfo,
                                 @RequestHeader("token") String token) {
        Long userId = JwtUtils.getUserId(token);
        borrowInfoService.saveBorrowInfo(borrowInfo, userId);
        return Response.ok().message("提交成功");
    }

}

